package com.example.fasttalk.setting;

import com.example.fasttalk.model.intfc.FastTalkSettingData;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import javax.swing.JComponent;
import javax.swing.JPanel;

/**
 * @author SundayLi
 * @date 2023/2/24 18:37
 */
public class FastTalkSettingsComponent implements FastTalkSettingData {
  private final JPanel myMainPanel;
  private final JBTextField userNameText = new JBTextField();
  private final JBTextField passwordText = new JBTextField();
  private final JBTextField serverUrlText = new JBTextField();
  private final JBTextField emoticonPathText = new JBTextField();

  public FastTalkSettingsComponent() {
    myMainPanel = FormBuilder.createFormBuilder()
      .addLabeledComponent(new JBLabel("user name: "), userNameText, 1, false)
      .addLabeledComponent(new JBLabel("password: "), passwordText, 1, false)
      .addLabeledComponent(new JBLabel("server url: "), serverUrlText, 1, false)
      .addLabeledComponent(new JBLabel("emoticon path: "), emoticonPathText, 1, false)
      .addComponentFillVertically(new JPanel(), 0)
      .getPanel();
  }

  public JPanel getPanel() {
    return myMainPanel;
  }

  public JComponent getPreferredFocusedComponent() {
    return userNameText;
  }

  @Override
  public String getPassword() {
    return passwordText.getText();
  }

  @Override
  public void setPassword(String password) {
    passwordText.setText(password);
  }

  @Override
  public String getServerUrl() {
    return serverUrlText.getText();
  }

  @Override
  public void setServerUrl(String serverUrl) {
    serverUrlText.setText(serverUrl);
  }

  @Override
  public String getEmoticonPath() {
    return emoticonPathText.getText();
  }

  @Override
  public void setEmoticonPath(String emoticonPath) {
    emoticonPathText.setText(emoticonPath);
  }

  @Override
  public String getUserName() {
    return userNameText.getText();
  }

  @Override
  public void setUserName(String userName) {
    userNameText.setText(userName);
  }
}
